#lang autolisp

(setq epsilon 0.0001)

(check-equal? (+ 1 2) 3)
(check-equal? (+ 1 2 3 4.5) 10.5)
(check-equal? (+ 1 2 3 4.0) 10.0)
(check-equal? (- 50 40) 10)
(check-equal? (- 50 40.0) 10.0)
(check-equal? (- 50 40.0 2.5) 7.5)
(check-equal? (- 8) -8)
(check-equal? (* 2 3) 6)
(check-equal? (* 2 3.0) 6.0)
(check-equal? (* 2 3 4.0) 24.0)
(check-equal? (* 3 -4.5) -13.5)
(check-equal? (* 3) 3)
(check-equal? (/ 100 2) 50)
(check-equal? (/ 100 2.0) 50.0)
(check-equal? (/ 100 20.0 2) 2.5)
(check-equal? (/ 100 20 2) 2)
(check-equal? (/ 4) 4)
(check-equal? (= 4 4.0) t)
(check-equal? (= 20 388) nil)
(check-equal? (= 2.4 2.4 2.4) t)
(check-equal? (= 499 499 500) nil)
(check-equal? (= "me" "me") t)
(check-equal? (= "me" "you") nil)
(check-equal? (/= 10 20) t)
(check-equal? (/= "you" "you") nil)
(check-equal? (/= 5.43 5.44) t)
(check-equal? (/= 10 20 10 20 20) nil)
(check-equal? (/= 10 20 10 20) t)
(check-equal? (< 10 20) t)
(check-equal? (< "b" "c") t)
(check-equal? (< 357 33.2) nil)
(check-equal? (< 2 3 88) t)
(check-equal? (< 2 3 4 4) nil)
(check-equal? (<= 10 20) t)
(check-equal? (<= "b" "b") t)
(check-equal? (<= 357 33.2) nil)
(check-equal? (<= 2 9 9) t)
(check-equal? (<= 2 9 4 5) nil)
(check-equal? (> 120 17) t)
(check-equal? (> "c" "b") t)
(check-equal? (> 3.5 1792) nil)
(check-equal? (> 77 4 2) t)
(check-equal? (> 77 4 4) nil)
(check-equal? (>= 120 17) t)
(check-equal? (>= "c" "c") t)
(check-equal? (>= 3.5 1792) nil)
(check-equal? (>= 77 4 4) t)
(check-equal? (>= 77 4 9) nil)
(check-equal? (~ 3) -4)
(check-equal? (~ 100) -101)
(check-equal? (~ -4) 3)
(check-equal? (1+ 5) 6)
(check-equal? (1+ -17.5) -16.5)
(check-equal? (1- 5) 4)
(check-equal? (1- -17.5) -18.5)
(check-equal? (abs 100) 100)
(check-equal? (abs -100) 100)
(check-equal? (abs -99.25) 99.25)
(check-equal? (acad_strlsort '("Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec")) '("Apr" "Aug" "Dec" "Feb" "Jan" "Jul" "Jun" "Mar" "May" "Nov" "Oct" "Sep"))
;(check-equal? (getcname "ETIRER") "_STRETCH")
;(check-equal? (getcname "_STRETCH") "ETIRER")
(setq a 123 r 3.45 s "Hello!" x '(a b c))
;(setq f (open "name" "r"))
(check-equal? (type 'a) 'SYM)
(check-equal? (type a) 'INT)
;(check-equal? (type f) 'FILE)
(check-equal? (type r) 'REAL)
(check-equal? (type s) 'STR)
(check-equal? (type x) 'LIST)
(check-equal? (type +) 'SUBR)
(check-equal? (type nil) nil)
(setq a 103 b nil c "string")
(check-equal? (and 1.4 a c) t)
(check-equal? (and 1.4 a b c) nil)
(check-= (angle '(1.0 1.0) '(1.0 4.0)) 1.5708 epsilon)
(check-= (angle '(5.0 1.33) '(2.4 1.33)) 3.14159 epsilon)
(check-= (angtof "45.0000") 0.785398 epsilon)
(check-= (angtof "45.0000" 3) 1.0177 epsilon)
#|(check-equal? (angtos 0.785398 0 4) "45.0000")
(check-equal? (angtos -0.785398 0 4) "315.0000")
(check-equal? (angtos -0.785398 4) "S 45d E")
|#(check-equal? (append '(a b) '(c d)) '(A B C D))
(check-equal? (append '((a)(b)) '((c)(d))) '((A) (B) (C) (D)))
#|(check-equal? (apply '+ '(1 2 3)) 6)
(check-equal? (apply 'strcat '("a" "b" "c")) "abc")
|#(check-equal? (ascii "A") 65)
(check-equal? (ascii "a") 97)
(check-equal? (ascii "BIG") 66)
(setq al '((name box) (width 3) (size 4.7263) (depth 5)))
(check-equal? al '((NAME BOX) (WIDTH 3) (SIZE 4.7263) (DEPTH 5)))
(check-equal? (assoc 'size al) '(SIZE 4.7263))
(check-equal? (assoc 'weight al) nil)
(check-= (atan 1) 0.785398 epsilon)
(check-= (atan 1.0) 0.785398 epsilon)
(check-= (atan 0.5) 0.463648 epsilon)
(check-= (atan 1.0) 0.785398 epsilon)
(check-= (atan -1.0) -0.785398 epsilon)
(check-= (atan 2.0 3.0) 0.588003 epsilon)
(check-= (atan 2.0 -3.0) 2.55359 epsilon)
(check-= (atan 1.0 0.0) 1.5708 epsilon)
(check-equal? (atof "97.1") 97.1)
(check-equal? (atof "3") 3.0)
(check-equal? (atof "3.9") 3.9)
(check-equal? (atoi "97") 97)
(check-equal? (atoi "3") 3)
(check-equal? (atoi "3.9") 3)
(check-equal? (setq a '(x y z)) '(X Y Z))
(check-equal? (setq b 'a) 'A)
(check-equal? (atom 'a) t)
(check-equal? (atom a) nil)
(check-equal? (atom 'b) t)
(check-equal? (atom b) t)
(check-equal? (atom '(a b c)) nil)
#|(check-equal? (atoms-family 1 '("CAR" "CDR" "XYZ")) '("CAR" "CDR" nil))
(check-equal? (Boole 1 12 5) 4)
(check-equal? (Boole 6 6 5) 3)
(check-equal? (Boole 4 3 14) 12)
(check-equal? (setq a 2 b nil) nil)
(check-equal? (boundp 'a) t)
(check-equal? (boundp 'b) nil)
|#(setq pt3 '(5.25 1.0 3.0))(check-equal? pt3 '(5.25 1.0 3.0))
(check-equal? (caddr pt3) 3.0)
(check-equal? (caddr '(5.25 1.0)) nil)
(setq pt2 '(5.25 1.0))(check-equal? pt2 '(5.25 1.0))
(check-equal? (cadr pt2) 1.0)
(check-equal? (cadr '(4.0)) nil)
(check-equal? (cadr '(5.25 1.0 3.0)) 1.0)
(check-equal? (car '(a b c)) 'A)
(check-equal? (car '((a b) c)) '(A B))
(check-equal? (car '()) nil)
(check-equal? (cdr '(a b c)) '(B C))
(check-equal? (cdr '((a b) c)) '(C))
(check-equal? (cdr '()) nil)
(check-equal? (cdr '(a . b)) 'B)
(check-equal? (cdr '(1 . "Text")) "Text")
(check-equal? (chr 65) "A")
(check-equal? (chr 66) "B")
(check-equal? (chr 97) "a")
(setq pt1 '(1 1) pt2 '(1 5))(check-equal? pt2 '(1 5))
(check-equal? (cons 'a '(b c d)) '(A B C D))
(check-equal? (cons '(a) '(b c d)) '((A) B C D))
(check-equal? (cons 'a 2) '(A . 2))
(check-equal? (cos 0.0) 1.0)
(check-equal? (cos pi) -1.0)
#|(check-equal? (cvunit 1 "minute" "second") 60.0)
(check-equal? (cvunit 1 "gallon" "furlong") nil)
(check-equal? (cvunit 1.0 "inch" "cm") 2.54)
(check-equal? (cvunit 1.0 "acre" "sq yard") 4840.0)
(check-equal? (cvunit '(1.0 2.5) "ft" "in") '(12.0 30.0))
(check-equal? (cvunit '(1 2 3) "ft" "in") '(12.0 24.0 36.0))
|#(check-= (distance '(1.0 2.5 3.0) '(7.7 2.5 3.0)) 6.7 epsilon)
(check-= (distance '(1.0 2.0 0.5) '(3.0 4.0 0.5)) 2.82843 epsilon)
(setq f1 '(a b c))
(setq f2 '(a b c))
(setq f3 f2)
(check-equal? (eq f1 f3) nil)
(check-equal? (eq f3 f2) t)
(check-equal? (equal f1 f3) t)
(check-equal? (equal f3 f2) t)
(setq a 1.123456)
(setq b 1.123457)
(check-equal? (equal a b) nil)
(check-equal? (equal a b 0.000001) t)
(check-equal? (setq a 123) 123)
(check-equal? (setq b 'a) 'A)
(check-equal? (eval 4.0) 4.0)
(check-equal? (eval (abs -10)) 10)
(check-equal? (eval a) 123)
;;(check-equal? (eval b) 103)
(check-= (exp 1.0) 2.71828 epsilon)
(check-= (exp 2.2) 9.02501 epsilon)
(check-= (exp -0.4) 0.67032 epsilon)
(check-equal? (expt 2 4) 16)
(check-equal? (expt 3.0 2.0) 9.0)
(check-equal? (fix 3) 3)
(check-equal? (fix 3.7) 3)
(check-equal? (float 3) 3.0)
(check-equal? (float 3.75) 3.75)
(check-equal-output? (foreach n '(a b c) (print n)) "
A 
B 
C " 'C)
(check-equal? (gcd 81 57) 3)
(check-equal? (gcd 12 20) 4)
(check-equal? (if (= 1 3) "YES!!" "no.") "no.")
(check-equal? (if (= 2 (+ 1 1)) "YES!!") "YES!!")
(check-equal? (if (= 2 (+ 3 4)) "YES!!") nil)
(setq a '(1.0 1.0) b '(9.0 9.0))
(setq c '(4.0 1.0) d '(4.0 2.0))
#|(check-equal? (inters a b c d) nil)
(check-equal? (inters a b c d t) nil)
(check-equal? (inters a b c d nil) '(4.0 4.0))
|#(check-equal? (itoa 33) "33")
(check-equal? (itoa -17) "-17")
(check-equal? (last '(a b c d e)) 'E)
(check-equal? (last '(a b c (d e))) '(D E))
(check-equal? (length '(a b c d)) 4)
(check-equal? (length '(a b (c d))) 3)
(check-equal? (length '()) 0)
(check-equal? (listp '(a b c)) t)
(check-equal? (listp 'a) nil)
(check-equal? (listp 4.343) nil)
(check-equal? (listp nil) t)
(setq v1 '(1 2 43))
(check-equal? (listp v1) t)
(check-= (log 4.5) 1.50408 epsilon)
(check-= (log 1.22) 0.198851 epsilon)
(check-equal? (logand 7 15 3) 3)
(check-equal? (logand 2 3 15) 2)
(check-equal? (logand 8 3 4) 0)
(check-equal? (logior 1 2 4) 7)
(check-equal? (logior 9 3) 11)
(check-equal? (lsh 2 1) 4)
(check-equal? (lsh 2 -1) 1)
(check-equal? (lsh 40 2) 160)
(setq a 10 b 20 c 30)
#|(check-equal? (mapcar '1+ (list a b c)) '(11 21 31))
|#(check-equal? (max 4.07 -144) 4.07)
(check-equal? (max -88 19 5 2) 19)
(check-equal? (max 2.1 4 8) 8.0)
(check-equal? (member 'c '(a b c d e)) '(C D E))
(check-equal? (member 'q '(a b c d e)) nil)
(check-equal? (min 683 -10.0) -10.0)
(check-equal? (min 73 2 48 5) 2)
(check-equal? (min 73.0 2 48 5) 2.0)
(check-equal? (min 2 4 6.7) 2.0)
(check-equal? (minusp -1) t)
(check-equal? (minusp -4.293) t)
(check-equal? (minusp 830.2) nil)
(check-equal? (setq a 123 b "string" c nil) nil)
(check-equal? (not a) nil)
(check-equal? (not b) nil)
(check-equal? (not c) t)
(check-equal? (not '()) t)
(check-equal? (nth 3 '(a b c d e)) 'D)
(check-equal? (nth 0 '(a b c d e)) 'A)
(check-equal? (nth 5 '(a b c d e)) nil)
(check-equal? (setq a 123 b "string" c nil) nil)
(check-equal? (null a) nil)
(check-equal? (null b) nil)
(check-equal? (null c) t)

(check-equal? (null '()) t)
(check-equal? (setq a 123 b 'a) 'A)
(check-equal? (numberp 4) t)
(check-equal? (numberp 3.8348) t)
(check-equal? (numberp "Howdy") nil)
(check-equal? (numberp a) t)
(check-equal? (numberp b) nil)
#|(check-equal? (numberp (eval b)) t)
|#(check-equal? (or nil 45 '()) t)
(check-equal? (or nil '()) nil)
#|(check-equal? (polar '(1 1 3.5) 0.785398 1.414214) '(2.0 2.0 3.5))
(check-equal? (polar '(1 1) 0.785398 1.414214) '(2.0 2.0))
|#(check-equal? (setq a 123 b '(a)) '(A))
(check-equal-output? (prin1 'a) "A" 'A)
(check-equal-output? (prin1 a) "123" 123)
(check-equal-output? (prin1 b) "(A)" '(A))
(check-equal-output? (prin1 (chr 2)) "\"\\u0002\"" "\002")
#|(check-equal? (read "hello") 'HELLO)
(check-equal? (read "hello there") 'HELLO)
(check-equal? (read "\"Hi Y'all\"") "Hi Y'all")
(check-equal? (read "(a b c)") '(A B C))
(check-equal? (read "(a b c) '(d)") '(A B C))
(check-equal? (read "1.2300") '1.23)
(check-equal? (read "87") '87)
(check-equal? (read "87 3.2") '87)
|#(check-equal? (using-input "ABC
" (read-char)) 65)
(check-equal? (using-input "ABC
" (progn (read-char) (read-char))) 66)
(check-equal? (using-input "ABC
" (progn (read-char) (read-char) (read-char))) 67)
(check-equal? (using-input "ABC
" (progn (read-char) (read-char) (read-char) (read-char))) 10)
(check-equal? (using-input "To boldly go
" (read-line)) "To boldly go")
(check-equal? (rem 42 12) 6)
(check-equal? (rem 12.0 16) 12.0)
(check-equal? (rem 26 7 2) 1)
(check-equal? (setq a 10 b 100) 100)
(check-equal? (repeat 4 (setq a (+ a 10)) (setq b (+ b 100))) 500)
(check-equal? (repeat 100 "Me" "You") "You")
(check-equal? (reverse '((a) b c)) '(C B (A)))
(setq x 17.5)(check-equal? x 17.5)
#|(check-equal? (setq fmtval (rtos x 1 4)) "1.7500E+01")
(check-equal? (setq fmtval (rtos x 2 2)) "17.50")
(check-equal? (setq fmtval (rtos x 3 2)) "1'-5.50\"")
(check-equal? (setq fmtval (rtos x 4 2)) "1'-5 1/2\"")
(check-equal? (setq fmtval (rtos x 5 2)) "17 1/2")
(check-equal? (setvar "unitmode" 1) 1)
(check-equal? (setq fmtval (rtos x 3 2)) "1'5.50\"")
(check-equal? (setq fmtval (rtos x 4 2)) "1'5-1/2\"")
(check-equal? (setq fmtval (rtos x 5 2)) "17-1/2")
(check-equal? (set (read "a") 5.0) 5.0)
|#
(setq a 5.0)
(setq b 123 c 4.7)
(setq s "it")
(setq x '(a b))
(check-= (sin 1.0) 0.841471 epsilon)
(check-equal? (sin 0.0) 0.0)
(check-equal? (sqrt 4) 2.0)
(check-= (sqrt 2.0) 1.41421 epsilon)
(check-equal? (strcase "Sample") "SAMPLE")
(check-equal? (strcase "Sample" t) "sample")
(check-equal? (strcat "a" "bout") "about")
(check-equal? (strcat "a" "b" "c") "abc")
(check-equal? (strcat "a" "" "c") "ac")
(check-equal? (strcat) "")
(check-equal? (strlen "abcd") 4)
(check-equal? (strlen "ab") 2)
(check-equal? (strlen "one" "two" "four") 10)
(check-equal? (strlen) 0)
(check-equal? (strlen "") 0)
(setq sample '(a b (c d) b))
(check-equal? (subst 'qq 'b sample) '(A QQ (C D) QQ))
(check-equal? (subst 'qq 'z sample) '(A B (C D) B))
(check-equal? (subst 'qq '(c d) sample) '(A B QQ B))
(check-equal? (subst '(qq rr) '(c d) sample) '(A B (QQ RR) B))
(check-equal? (subst '(qq rr) 'z sample) '(A B (C D) B))
(setq who '((first john) (mid q) (last public)))
(setq old (assoc 'first who) new '(first j))
(check-equal? (subst new old who) '((FIRST J) (MID Q) (LAST PUBLIC)))
(check-equal? (substr "abcde" 2) "bcde")
(check-equal? (substr "abcde" 2 1) "b")
(check-equal? (substr "abcde" 3 2) "cd")
(check-equal? (ver) "Visual LISP 2010 (en)")
#|(check-equal? (wcmatch "Name" "N*") t)
(check-equal? (wcmatch "Name" "???,~*m*,N*") t)
(check-equal? (wcmatch "Name" "*`,*") nil)
(check-equal? (wcmatch "Name" "*`\\*") nil)
|#(check-equal-output? (write-char 67) "C" 67)
(check-equal? (zerop 0) t)
(check-equal? (zerop 0.0) t)
(check-equal? (zerop 0.0001) nil)


